<?php
/**
 * 时区配置
 * 
 * $Id: timezone.functions.php 122 2010-05-28 10:05:16Z Administrator $
 * $Revision: 122 $
 * $Author: Administrator $
 * $Date: 2010-05-28 10:05:16 +0000 (Fri, 28 May 2010) $
 * 本功能模块可以取得所有的时区并能进行时区设置
 * 
 * 
 * @author glzaboy<glzaboy@163.com>
 * @package fastlib
 * @subpackage functions
 * @copyright 2005-2010 (c) glzaboy
 */
/**
 * 返回正在使用的默认时区
 *
 * @return string
 */
function timezoneGet() {
	return date_default_timezone_get ();
}
/**
 * 设置时区
 *
 * @param string $timezone
 * @return bool 
 */
function timezoneSet($timezone) {
	$timezone = trim ( $timezone );
	if (function_exists ( 'date_default_timezone_set' ) && $timezone) {
		if (substr ( $timezone, 0, 7 ) == 'Etc/GMT') {
			$timezone = strtr ( $timezone, array ('-' => '+', '+' => '-' ) );
		}
		return date_default_timezone_set ( $timezone );
	}
	return false;
}
/**
 * 时区列表
 *
 * $method 0时显示文字时区
 * $method 1时显示GMT时区
 * $method 2时显示文字和GMT时区
 * 
 * @param $method int 输出方法0,1,2 
 * @return array 时区列表
 */
function timezoneList($method = 0) {
	$offset_range = array (- 12, - 11, - 10, - 9, - 8, - 7, - 6, - 5, - 4, - 3, - 2, - 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 );
	if (function_exists ( 'timezone_identifiers_list' ) && ($method == 0 or $method == 2)) {
		$continents = array ('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' );
		$timezone = array ();
		foreach ( timezone_identifiers_list ( 16, '' ) as $zone ) {
			$zone = explode ( '/', $zone );
			if (! in_array ( $zone [0], $continents )) {
				continue;
			}
			$timezone [$zone [0]] [] = $zone [1];
		}
	}
	if ($method == 1 or $method == 2 or (! function_exists ( 'timezone_identifiers_list' ) && $method == 0)) {
		foreach ( $offset_range as $offset ) {
			if (0 <= $offset) {
				$offset_name = '+' . $offset;
			} else {
				$offset_name = ( string ) $offset;
			}
			$timezone ['GMT'] [] = 'Etc/GMT' . $offset_name;
		}
	}
	return $timezone;
}
/**
 * 返回本模块信息
 *
 * @return string
 */
function timezoneprintInfo() {
	$version = '$Revision: 122 $';
	$moudle = explode ( "functions", __FILE__ );
	$moudle = $moudle [1] ? substr ( $moudle [1], 1 ) . 'functions' : $moudle;
	$return = '';
	$return .= startTable ();
	$return .= printRow ( array (array ('class' => 'h', 'content' => '<center>' . $moudle . '</center>', 'colspan' => '2' ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'author' ), array ('class' => 'v', 'content' => 'glzaboy' ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'version' ), array ('class' => 'v', 'content' => $version ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'suport' ), array ('class' => 'v', 'content' => 'timezone list set get' ) ) );
	$return .= endTable ();
	return $return;
}